// The MIT License (MIT)

// Copyright (c) 2016, 2017, 2019 by German A. Arias

// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in 
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

#include "eiffel-iup-cecil.h"


int iup_init(int argc, char *argv[]) {
   /* This is called in all IUP applications. Arguments are parsed
    * from the command line and are returned to the application. */
   IupOpen(&argc, &argv);
   return argc;
}

void iup_main_loop() {
  IupMainLoop();
}

void iup_close() {
  IupClose();
}

int get_param_dialog (const char* title, void* user_data, const char* format, int param_count, int param_extra, void** param_data) {
  return IupGetParamv(title, param_action, user_data, format, param_count, param_extra, param_data);
}

int param_action(Ihandle* dialog, int param_index, void* user_data) {
  return param_cb_FniV(iup_object(0), dialog, param_index, user_data);
}

void config_recent_init (Ihandle* ih, Ihandle* menu, int max_recent) {
  IupConfigRecentInit(ih, menu, (Icallback) callback_recent_cb, max_recent);
}

void connect_function (const char *name, int operation) {
  
  if (strcmp("IDLE_ACTION",name) == 0)
    {
      if (operation == 1)
	{
	  IupSetFunction(name, (Icallback) callback_idle_action);
	}
      else
	{
	  IupSetFunction(name, NULL);
	}
    }
  else
    {
      printf("Unknown function.");
    }
}

void connect_callback (Ihandle* ih, const char *name, const char *type, int operation) {

  if (operation == 0)
    {
      IupSetCallback(ih, name, NULL);
      return;
    }

  if (strcmp("HELP_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_map_cb);
    }
  else if (strcmp("MAP_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_map_cb);
    }
  else if (strcmp("UNMAP_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_unmap_cb);
    }
  else if (strcmp("DESTROY_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_destroy_cb);
    }
  else if (strcmp("LDESTROY_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_ldestroy_cb);
    }
  else if (strcmp("GETFOCUS_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_getfocus_cb);
    }
  else if (strcmp("KILLFOCUS_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_killfocus_cb);
    }
  else if (strcmp("ENTERWINDOW_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_enterwindow_cb);
    }
  else if (strcmp("LEAVEWINDOW_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_leavewindow_cb);
    }
  else if (strcmp("K_ANY",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_k_any);
    }
  else if (strcmp("ACTION",name) == 0)
    {
      if (strcmp("Fn", type) == 0)
	{
	  IupSetCallback(ih, name, (Icallback) callback_action_Fn);
	}
      else if (strcmp("Fnff", type) == 0)
	{
	  IupSetCallback(ih, name, (Icallback) callback_action_Fnff);
	}
      else if (strcmp("Fns", type) == 0)
	{
	  IupSetCallback(ih, name, (Icallback) callback_click_cb);
	}
      else if (strcmp("Fnsii", type) == 0)
	{
	  IupSetCallback(ih, name, (Icallback) callback_action_Fnsii);
	}
      else if (strcmp("Fnis", type) == 0)
	{
	  IupSetCallback(ih, name, (Icallback) callback_action_Fnis);
	}
      else if (strcmp("Fni", type) == 0)
	{
	  IupSetCallback(ih, name, (Icallback) callback_action_Fni);
	}
    }
  else if (strcmp("CLOSE_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_close_cb);
    }
  else if (strcmp("COPYDATA_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_copydata_cb);
    }
  else if (strcmp("DROPFILES_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_dropfiles_cb);
    }
  // Skeep CUSTOMFRAME_CB
  else if (strcmp("MDIACTIVATE_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_mdiactivate_cb);
    }
  else if (strcmp("MOVE_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_move_cb);
    }
  else if (strcmp("RESIZE_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_resize_cb);
    }
  else if (strcmp("SHOW_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_show_cb);
    }
  else if (strcmp("TRAYCLICK_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_trayclick_cb);
    }
  else if (strcmp("FILE_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_file_cb);
    }
  else if (strcmp("COLORUPDATE_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_colorupdate_cb);
    }
  else if (strcmp("CANCEL_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_cancel_cb);
    }
  else if (strcmp("GETPARAM",name) == 0)
    {
    }
  else if (strcmp("TABCHANGE_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_tabchange_cb);
    }
  else if (strcmp("TABCHANGEPOS_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_tabchangepos_cb);
    }
  else if (strcmp("TABCLOSE_CB",name) == 0)
    {
       IupSetCallback(ih, name, (Icallback) callback_tabclose_cb);
    }
  else if (strcmp("RIGHTCLICK_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_rightclick_cb);
    }
  else if (strcmp("DETACHED_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_detached_cb);
    }
  else if (strcmp("RESTORED_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_restored_cb);
    }
  else if (strcmp("OPENCLOSE_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_openclose_cb);
    }
  else if (strcmp("EXTRABUTTON_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_extrabutton_cb);
    }
  else if (strcmp("VALUECHANGED_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_valuechanged_cb);
    }
  else if (strcmp("BUTTON_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_button_cb);
    }
  else if (strcmp("FOCUS_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_focus_cb);
    }
  else if (strcmp("MOTION_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_motion_cb);
    }
  else if (strcmp("KEYPRESS_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_keypress_cb);
    }
  else if (strcmp("SCROLL_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_scroll_cb);
    }
  // TOUCH_CB and MULTITOUCH_CB
  else if (strcmp("WHEEL_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_wheel_cb);
    }
  // WOM_CB
  else if (strcmp("CARET_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_caret_cb);
    }
  else if (strcmp("DBLCLICK_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_dblclick_cb);
    }
  else if (strcmp("DRAGDROP_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_dragdrop_cb);
    }
  else if (strcmp("DROPDOWN_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_dropdown_cb);
    }
  else if (strcmp("EDIT_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_edit_cb);
    }
  else if (strcmp("MULTISELECT_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_multiselect_cb);
    }
  else if (strcmp("SPIN_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_spin_cb);
    }
  else if (strcmp("SELECTION_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_selection_cb);
    }
  else if (strcmp("MULTISELECTION_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_multiselection_cb);
    }
  else if (strcmp("MULTIUNSELECTION_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_multiunselection_cb);
    }
  else if (strcmp("BRANCHOPEN_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_branchopen_cb);
    }
  else if (strcmp("BRANCHCLOSE_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_branchclose_cb);
    }
  else if (strcmp("EXECUTELEAF_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_executeleaf_cb);
    }
  else if (strcmp("SHOWRENAME_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_showrename_cb);
    }
  else if (strcmp("RENAME_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_rename_cb);
    }
  else if (strcmp("NODEREMOVED_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_noderemoved_cb);
    }
  else if (strcmp("TOGGLEVALUE_CB",name) == 0)
    {
      if (strcmp("Fnii", type) == 0)
	{
	  IupSetCallback(ih, name, (Icallback) callback_togglevalue_cb_Fnii);
	}
      // Matrix
      else if (strcmp("Fniii", type) == 0)
	{
	  IupSetCallback(ih, name, (Icallback) callback_togglevalue_cb_Fniii);
	}
    }
  else if (strcmp("HIGHLIGHT_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_highlight_cb);
    }
  else if (strcmp("OPEN_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_open_cb);
    }
  else if (strcmp("MENUCLOSE_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_menuclose_cb);
    }
  else if (strcmp("DRAGBEGIN_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_dragbegin_cb);
    }
  else if (strcmp("DRAGDATASIZE_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_dragdatasize_cb);
    }
  else if (strcmp("DRAGDATA_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_dragdata_cb);
    }
  else if (strcmp("DRAGEND_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_dragend_cb);
    }
  else if (strcmp("DROPDATA_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_dropdata_cb);
    }
  else if (strcmp("DROPMOTION_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_dropmotion_cb);
    }
  else if (strcmp("FLAT_ACTION",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_flat_action_Fn);
    }
  else if (strcmp("FLAT_BUTTON_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_flat_button_cb);
    }
  else if (strcmp("FLAT_FOCUS_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_flat_focus_cb);
    }
  else if (strcmp("FLAT_ENTERWINDOW_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_flat_enterwindow_cb);
    }
  else if (strcmp("FLAT_LEAVEWINDOW_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_flat_leavewindow_cb);
    }
  // Cells
  else if (strcmp("DRAW_CB",name) == 0) // Also Matrix
    {
      IupSetCallback(ih, name, (Icallback) callback_draw_cb);
    }
  else if (strcmp("HEIGHT_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_height_cb);
    }
  else if (strcmp("HSPAN_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_hspan_cb);
    }
  else if (strcmp("MOUSECLICK_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_mouseclick_cb);
    }
  else if (strcmp("MOUSEMOTION_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_mousemotion_cb);
    }
  else if (strcmp("NCOLS_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_ncols_cb);
    }
  else if (strcmp("NLINES_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_nlines_cb);
    }
  else if (strcmp("SCROLLING_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_scrolling_cb);
    }
  else if (strcmp("VSPAN_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_vspan_cb);
    }
  else if (strcmp("WIDTH_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_width_cb);
    }
  else if (strcmp("CELL_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_cell_cb);
    }
  else if (strcmp("EXTENDED_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_extended_cb);
    }
  else if (strcmp("SELECT_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_select_cb);
    }
  else if (strcmp("SWITCH_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_switch_cb);
    }
  // Matrix (Interaction)
  else if (strcmp("ACTION_CB", name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_action_Fniiiis);
    }
  else if (strcmp("CLICK_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_click_cb_Fniis);
    }
  else if (strcmp("COLRESIZE_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_colresize_cb);
    }
  else if (strcmp("RELEASE_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_release_cb);
    }
  else if (strcmp("RESIZEMATRIX_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_resizematrix_cb);
    }
  else if (strcmp("MOUSEMOVE_CB",name) == 0)
    {
      if (strcmp("Fnd", type) == 0)
	{
	  IupSetCallback(ih, name, (Icallback) callback_mousemove_cb_Fnd);
	}
      else
	{
	  IupSetCallback(ih, name, (Icallback) callback_mousemove_cb);
	}
    }
  else if (strcmp("ENTERITEM_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_enteritem_cb);
    }
  else if (strcmp("LEAVEITEM_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_leaveitem_cb);
    }
  else if (strcmp("SCROLLTOP_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_scrolltop_cb);
    }
  else if (strcmp("BGCOLOR_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_bgcolor_cb);
    }
  else if (strcmp("FGCOLOR_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_fgcolor_cb);
    }
  else if (strcmp("FONT_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_font_cb);
    }
  else if (strcmp("TYPE_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_type_cb);
    }
  else if (strcmp("DROPCHECK_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_dropcheck_cb);
    }
  else if (strcmp("TRANSLATEVALUE_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_translatevalue_cb);
    }
  else if (strcmp("DROP_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_drop_cb);
    }
  else if (strcmp("MENUDROP_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_menudrop_cb);
    }
  else if (strcmp("DROPSELECT_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_dropselect_cb);
    }
  else if (strcmp("EDITION_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_edition_cb);
    }
  else if (strcmp("VALUE_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_value_cb);
    }
  else if (strcmp("VALUE_EDIT_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_value_edit_cb);
    }
  else if (strcmp("MARK_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_mark_cb);
    }
  else if (strcmp("MARKEDIT_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_markedit_cb);
    }
  // Flat tabs
  else if (strcmp("FLAT_MOTION_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_flat_motion_cb);
    }
  // Drop button
  else if (strcmp("DROPSHOW_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_flat_dropshow_cb);
    }
  // Dial
  else if (strcmp("BUTTON_PRESS_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_button_press_cb);
    }
  else if (strcmp("BUTTON_RELEASE_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_button_release_cb);
    }
  // Color browse
  else if (strcmp("CHANGE_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_change_cb);
    }
  else if (strcmp("DRAG_CB",name) == 0)
    {
      IupSetCallback(ih, name, (Icallback) callback_drag_cb);
    }
  else
    {
      printf("Unknown function.");
    }
}

// One function for each type of event

// Common callbacks
int callback_idle_action(void) {
  return idle_action_Fidle(iup_object(0));
}

void callback_help_cb(Ihandle *ih) {
  help_cb_Fn(iup_object(0), ih);
}

int callback_map_cb(Ihandle *ih) {
  return map_cb_Fn(iup_object(0), ih);
}

int callback_unmap_cb(Ihandle *ih) {
  return unmap_cb_Fn(iup_object(0), ih);
}

int callback_destroy_cb(Ihandle *ih) {
  return destroy_cb_Fn(iup_object(0), ih);
}

int callback_ldestroy_cb(Ihandle *ih) {
  return ldestroy_cb_Fn(iup_object(0), ih);
}

int callback_getfocus_cb(Ihandle *ih) {
  return getfocus_cb_Fn(iup_object(0), ih);
}

int callback_killfocus_cb(Ihandle *ih) {
  return killfocus_cb_Fn(iup_object(0), ih);
}

int callback_enterwindow_cb(Ihandle *ih) {
  return enterwindow_cb_Fn(iup_object(0), ih);
}

int callback_leavewindow_cb(Ihandle *ih) {
  return leavewindow_cb_Fn(iup_object(0), ih);
}

int callback_k_any(Ihandle *ih, int c) {
  return k_any_Fni(iup_object(0), ih, c);
}

// Action callbacks
int callback_action_Fn(Ihandle *ih) {
  return action_Fn(iup_object(0), ih);
}

// Dialog and progress dialog callback
int callback_close_cb(Ihandle *ih) {
  return close_cb_Fn(iup_object(0), ih);
}

int callback_copydata_cb(Ihandle *ih, char* cmdLine, int size) {
  return copydata_cb_Fnsi(iup_object(0), ih, cmdLine, size);
}

int callback_dropfiles_cb(Ihandle *ih, char* filename, int num, int x, int y) {
  return dropfiles_cb_Fnsiii(iup_object(0), ih, filename, num, x, y);
}

int callback_mdiactivate_cb(Ihandle *ih) {
  return mdiactivate_cb_Fn(iup_object(0), ih);
}

int callback_move_cb(Ihandle *ih, int x, int y) {
  return move_cb_Fnii(iup_object(0), ih, x, y);
}

int callback_resize_cb(Ihandle *ih, int width, int height) {
  return resize_cb_Fnii(iup_object(0), ih, width, height);
}

int callback_show_cb(Ihandle *ih, int state) {
  return show_cb_Fni(iup_object(0), ih, state);
}

int callback_trayclick_cb(Ihandle *ih, int but, int pressed, int dclick) {
  return trayclick_cb_Fniii(iup_object(0), ih, but, pressed, dclick);
}

// File dialog callback
int callback_file_cb(Ihandle *ih, char* file_name, char* status) {
  return file_cb_Fnss(iup_object(0), ih, file_name, status);
}

// Color dialog callback
int callback_colorupdate_cb (Ihandle* ih) {
  return colorupdate_cb_Fn(iup_object(0), ih);
}

// Progress dialog callback
int callback_cancel_cb (Ihandle* ih) {
  return cancel_cb_Fn(iup_object(0), ih);
}
/*
// Get param dialog callback
int callback_getparam(Ihandle* dialog, int param_index, void* user_data) {
  return getparam_FniV(iup_object(0), dialog, param_index, user_data);  
}
*/

// Tabs callbacks

int callback_tabchange_cb(Ihandle *ih, Ihandle* new_tab, Ihandle* old_tab) {
  return tabchange_cb_Fnnn(iup_object(0), ih, new_tab, old_tab);
}

int callback_tabchangepos_cb(Ihandle *ih, int new_pos, int old_pos) {
  return tabchangepos_cb_Fnii(iup_object(0), ih, new_pos, old_pos);
}

int callback_tabclose_cb(Ihandle *ih, int pos) {
  return tabclose_cb_Fni(iup_object(0), ih, pos);
}

int callback_rightclick_cb(Ihandle *ih, int pos) {
  return rightclick_cb_Fni(iup_object(0), ih, pos);
}

// Detach box callback
int callback_detached_cb(Ihandle *ih, Ihandle *new_parent, int x, int y) {
  return detached_cb_Fnnii(iup_object(0), ih, new_parent, x, y);
}

int callback_restored_cb(Ihandle *ih, Ihandle *old_parent, int x, int y) {
  return restored_cb_Fnnii(iup_object(0), ih, old_parent, x, y);
}

// Expander callbacks
int callback_openclose_cb(Ihandle *ih, int state) {
  return openclose_cb_Fni(iup_object(0), ih, state);
}

int callback_extrabutton_cb(Ihandle *ih, Ihandle *new_parent, int button, int pressed) {
  return extrabutton_cb_Fnii(iup_object(0), ih, button, pressed);
}

// Val callback
int callback_valuechanged_cb(Ihandle *ih) {
  return valuechanged_cb_Fn(iup_object(0), ih); // Also matrix
}

// Button callback
int callback_button_cb(Ihandle *ih, int button, int pressed, int x, int y, char* status) {
  return button_cb_Fniiiis(iup_object(0), ih, button, pressed, x, y, status);
}

// Canvas callbacks
int callback_action_Fnff(Ihandle *ih, float posx, float posy) {
  return action_Fnff(iup_object(0), ih, posx, posy);
}
// Also Dialog
int callback_focus_cb(Ihandle *ih, int focus) {
  return focus_cb_Fni(iup_object(0), ih, focus);
}

int callback_motion_cb(Ihandle *ih, int x, int y, char *status) {
  return motion_cb_Fniis(iup_object(0), ih, x, y, status);
}

int callback_keypress_cb(Ihandle *ih, int c, int press) {
  return keypress_cb_Fnii(iup_object(0), ih, c, press);
}

int callback_scroll_cb(Ihandle *ih, int op, float posx, float posy) {
  return scroll_cb_Fniff(iup_object(0), ih, op, posx, posy);
}

int callback_wheel_cb(Ihandle *ih, float delta, int x, int y, char *status) {
  return wheel_cb_Fndiis(iup_object(0), ih, delta, x, y, status);
}

int callback_click_cb(Ihandle *ih, char *url) {
  return click_cb_Fns(iup_object(0), ih, url);
}

// List callbacks
int callback_action_Fnsii(Ihandle *ih, char *text, int item, int state) {
  return action_Fnsii(iup_object(0), ih, text, item, state);
}

int callback_caret_cb(Ihandle *ih, int lin, int col, int pos) {
  return caret_cb_Fniii(iup_object(0), ih, lin, col, pos);
}

int callback_dblclick_cb(Ihandle *ih, int item, char *text) {
  return dblclick_cb_Fnis(iup_object(0), ih, item, text);
}

int callback_dragdrop_cb(Ihandle *ih, int drag_id, int drop_id, int isshift, int iscontrol) {
  return dragdrop_cb_Fniiii(iup_object(0), ih, drag_id, drop_id, isshift, iscontrol);
}

int callback_dropdown_cb(Ihandle *ih, int state) {
  return dropdown_cb_Fni(iup_object(0), ih, state);
}

int callback_edit_cb(Ihandle *ih, int c, char *new_value) {
  return edit_cb_Fnis(iup_object(0), ih, c, new_value);
}

int callback_multiselect_cb(Ihandle *ih, char *value) {
  return multiselect_cb_Fns(iup_object(0), ih, value);
}

// Spin callback
int callback_spin_cb(Ihandle *ih, int inc) {
  return spin_cb_Fni(iup_object(0), ih, inc);
}

// Text callback
int callback_action_Fnis(Ihandle *ih, int c, char *new_value) {
  return action_Fnis(iup_object(0), ih, c, new_value);
}

// Toggle callback
int callback_action_Fni(Ihandle* ih, int state) {
  return action_Fni(iup_object(0), ih, state);
}

// Tree callbacks
int callback_selection_cb (Ihandle *ih, int id, int status) {
  return selection_cb_Fnii(iup_object(0), ih, id, status);
}

int callback_multiselection_cb (Ihandle *ih, int* ids, int n) {
  return multiselection_cb_Fnpi(iup_object(0), ih, ids, n);
}

int callback_multiunselection_cb (Ihandle *ih, int* ids, int n) {
  return multiunselection_cb_Fnpi(iup_object(0), ih, ids, n);
}

int callback_branchopen_cb (Ihandle *ih, int id) {
  return branchopen_cb_Fni(iup_object(0), ih, id);
}

int callback_branchclose_cb (Ihandle *ih, int id) {
  return branchclose_cb_Fni(iup_object(0), ih, id);
}

int callback_executeleaf_cb (Ihandle *ih, int id) {
  return executeleaf_Cb_Fni(iup_object(0), ih, id);
}

int callback_showrename_cb (Ihandle *ih, int id) {
  return showrename_cb_Fni(iup_object(0), ih, id);
}

int callback_rename_cb (Ihandle *ih, int id, char *title) {
  return rename_cb_Fnis(iup_object(0), ih, id, title);
}

int callback_noderemoved_cb (Ihandle *ih, void* userdata) {
  return noderemoved_cb_Fns(iup_object(0), ih, userdata);
}

int callback_togglevalue_cb_Fnii (Ihandle *ih, int id, int state) {
  return togglevalue_cb_Fnii(iup_object(0), ih, id, state);
}

// Menu callbacks
int callback_highlight_cb (Ihandle *ih) {
  return highlight_cb_Fn(iup_object(0), ih);
}

int callback_open_cb (Ihandle *ih) {
  return open_cb_Fn(iup_object(0), ih);
}

int callback_menuclose_cb (Ihandle *ih) {
  return menuclose_cb_Fn(iup_object(0), ih);
}

// Drag&Drop callbacks
int callback_dragbegin_cb (Ihandle* ih, int x, int y) {
  return dragbegin_cb_Fnii(iup_object(0), ih, x, y);
}

int callback_dragdatasize_cb (Ihandle* ih, char* type) {
  return dragdatasize_cb_Fns(iup_object(0), ih, type);
}

int callback_dragdata_cb (Ihandle* ih, char* type, void* data, int size) {
  return dragdata_cb_FnsVi(iup_object(0), ih, type, data, size);
}

int callback_dragend_cb (Ihandle* ih, int action) {
  return dragend_cb_Fni(iup_object(0), ih, action);
}

int callback_dropdata_cb (Ihandle* ih, char* type, void* data, int size, int x, int y) {
  return dropdata_cb_FnsViii(iup_object(0), ih, type, data, size, x, y);
}

int callback_dropmotion_cb (Ihandle *ih, int x, int y, char *status) {
  return dropmotion_cb_Fniis(iup_object(0), ih, x, y, status);
}

// Menu recent files
int callback_recent_cb (Ihandle *ih) {
  return recent_cb_Fn (iup_object(0), ih);
}

// Flat button
int callback_flat_action_Fn(Ihandle *object) {
  return flat_action_Fn (iup_object(0), object);
}

int callback_flat_button_cb(Ihandle *ih, int button, int pressed, int x, int y, char* status) {
  return flat_button_cb_Fniiiis(iup_object(0), ih, button, pressed, x, y, status);
}

int callback_flat_focus_cb(Ihandle *ih, int focus) {
  return flat_focus_cb_Fni(iup_object(0), ih, focus);
}

int callback_flat_enterwindow_cb(Ihandle *ih) {
  return flat_enterwindow_cb_Fn(iup_object(0), ih);
}

int callback_flat_leavewindow_cb(Ihandle *ih) {
  return flat_leavewindow_cb_Fn(iup_object(0), ih);
}

// Cells
int callback_draw_cb(Ihandle* ih, int line, int column, int xmin, int xmax, int ymin, int ymax, cdCanvas* canvas) {
  return draw_cb_Fniiiiiic(iup_object(0), ih, line, column, xmin, xmax, ymin, ymax, canvas);
}

int callback_height_cb(Ihandle* ih, int line) {
  return height_cb_Fni(iup_object(0), ih, line);
}

int callback_hspan_cb(Ihandle* ih, int line, int column) {
  return hspan_cb_Fnii(iup_object(0), ih, line, column);
}

int callback_mouseclick_cb(Ihandle* ih, int button, int pressed, int line, int column, int x, int y, char* status) {
  return mouseclick_cb_Fniiiiiis(iup_object(0), ih, button, pressed, line, column, x, y, status);
}

int callback_mousemotion_cb(Ihandle *ih, int line, int column, int x, int y, char *r) {
  return mousemotion_cb_Fniiiis(iup_object(0), ih, line, column, x, y, r);
}

int callback_ncols_cb(Ihandle* ih) {
  return ncols_cb_Fn(iup_object(0), ih);
}

int callback_nlines_cb(Ihandle* ih) {
  return nlines_cb_Fn(iup_object(0), ih);
}

int callback_scrolling_cb(Ihandle* ih, int line, int column) {
  return scrolling_cb_Fnii(iup_object(0), ih, line, column);
}

int callback_vspan_cb(Ihandle* ih, int line, int column) {
  return vspan_cb_Fnii(iup_object(0), ih, line, column);
}

int callback_width_cb(Ihandle* ih, int column) {
  return width_cb_Fni(iup_object(0), ih, column);
}

// Color bar

char* callback_cell_cb(Ihandle* ih, int cell) {

  unsigned char r, g, b;
  long int cl;
  static char str[30];

  cl = cell_cb_Fni(iup_object(0), ih, cell);

  if (cl == -1)
    {
      return NULL;
    }
  else
    {
      cdDecodeColor(cl, &r, &g, &b);
      sprintf(str, "%d %d %d", (int)r, (int)g, (int)b);

      return str;
    }
}

int callback_extended_cb(Ihandle* ih, int cell) {
  return extended_cb_Fni(iup_object(0), ih, cell);
}

int callback_select_cb(Ihandle* ih, int cell, int type) {
  return select_cb_Fnii(iup_object(0), ih, cell, type);
}

int callback_switch_cb(Ihandle* ih, int prim_cell, int sec_cell) {
  return switch_cb_Fnii(iup_object(0), ih, prim_cell, sec_cell);
}

// Matrix
int callback_action_Fniiiis(Ihandle *ih, int key, int lin, int col, int edition, char* value) {
  return action_Fniiiis(iup_object(0), ih, key, lin, col, edition, value);
}

int callback_click_cb_Fniis (Ihandle *ih, int lin, int col, char *status) {
  return click_cb_Fniis(iup_object(0), ih, lin, col, status);
}

int callback_colresize_cb (Ihandle *ih, int col) {
  return colresize_cb_Fni(iup_object(0), ih, col);
}

int callback_release_cb (Ihandle *ih, int lin, int col, char *status) {
  return release_cb_Fniis(iup_object(0), ih, lin, col, status);
}

int callback_resizematrix_cb (Ihandle *ih, int width, int height) {
  return resizematrix_cb_Fnii(iup_object(0), ih, width, height);
}

int callback_mousemove_cb (Ihandle *ih, int lin, int col) {
  return mousemove_cb_Fnii(iup_object(0), ih, lin, col);
}

int callback_enteritem_cb (Ihandle *ih, int lin, int col) {
  return enteritem_cb_Fnii(iup_object(0), ih, lin, col);
}

int callback_leaveitem_cb (Ihandle *ih, int lin, int col) {
  return leaveitem_cb_Fnii(iup_object(0), ih, lin, col);
}

int callback_scrolltop_cb (Ihandle *ih, int lin, int col) {
  return scrolltop_cb_Fnii(iup_object(0), ih, lin, col);
}

int callback_bgcolor_cb (Ihandle *ih, int lin, int col, int *red, int *green, int *blue) {
  return bgcolor_cb_FniiVVV(iup_object(0), ih, lin, col, red, green, blue);
}

int callback_fgcolor_cb (Ihandle *ih, int lin, int col, int *red, int *green, int *blue) {
  return fgcolor_cb_FniiVVV(iup_object(0), ih, lin, col, red, green, blue);
}

char* callback_font_cb (Ihandle* ih, int lin, int col) {
  return font_cb_Fnii (iup_object(0), ih, lin, col);
}

char* callback_type_cb (Ihandle* ih, int lin, int col) {
  return type_cb_Fnii (iup_object(0), ih, lin, col);
}

int callback_dropcheck_cb (Ihandle *ih, int lin, int col) {
  return dropcheck_cb_Fnii (iup_object(0), ih, lin, col);
}

char* callback_translatevalue_cb (Ihandle* ih, int lin, int col, char* value) {
  return translatevalue_cb_Fniis (iup_object(0), ih, lin, col, value);
}

int callback_togglevalue_cb_Fniii (Ihandle *ih, int lin, int col, int status) {
  return togglevalue_cb_Fniii (iup_object(0), ih, lin, col, status);
}

int callback_drop_cb (Ihandle *ih, Ihandle *drop, int lin, int col) {
  return drop_cb_Fnnii (iup_object(0), ih, drop, lin, col);
}

int callback_menudrop_cb (Ihandle *ih, Ihandle *drop, int lin, int col) {
  return menudrop_cb_Fnnii (iup_object(0), ih, drop, lin, col);
}

int callback_dropselect_cb (Ihandle *ih, int lin, int col, Ihandle *drop, char *t, int i, int v) {
  return dropselect_cb_Fniinsii (iup_object(0), ih, lin, col, drop, t, i, v);
}

int callback_edition_cb (Ihandle *ih, int lin, int col, int mode, int update) {
  return edition_cb_Fniiii (iup_object(0), ih, lin, col, mode, update);
}

char* callback_value_cb (Ihandle* ih, int lin, int col) {
  return value_cb_Fnii (iup_object(0), ih, lin, col);
}

int callback_value_edit_cb (Ihandle *ih, int lin, int col, char* newval) {
  return value_edit_cb_Fniis (iup_object(0), ih, lin, col, newval);
}

int callback_mark_cb (Ihandle* ih, int lin, int col) {
  return mark_cb_Fnii (iup_object(0), ih, lin, col);
}

int callback_markedit_cb (Ihandle *ih, int lin, int col, int marked) {
  return markedit_cb_Fniii (iup_object(0), ih, lin, col, marked);
}

// Flat tabs

int callback_flat_motion_cb(Ihandle *ih, int x, int y, char *status) {
  return flat_motion_cb_Fniis(iup_object(0), ih, x, y, status);
}

// Drop button

int callback_flat_dropshow_cb (Ihandle *ih, int state) {
  return flat_dropshow_cb_Fni(iup_object(0), ih, state);
}

// Dial

int callback_button_press_cb (Ihandle *ih, double angle) {
  return button_press_cb_Fnd(iup_object(0), ih, angle);
}

int callback_button_release_cb (Ihandle *ih, double angle) {
  return button_release_cb_Fnd(iup_object(0), ih, angle);
}

int callback_mousemove_cb_Fnd (Ihandle *ih, double angle) {
  return mousemove_cb_Fnd(iup_object(0), ih, angle);
}

// Color browse

int callback_change_cb (Ihandle *ih, unsigned char r, unsigned char g, unsigned char b) {
  return change_cb_FnVVV(iup_object(0), ih, (int) r, (int) g, (int) b);
}

int callback_drag_cb (Ihandle *ih, unsigned char r, unsigned char g, unsigned char b) {
  return drag_cb_FnVVV(iup_object(0), ih, (int) r, (int) g, (int) b);
}

